﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class XTJCreateRoom : MonoBehaviour {

    EginUser user = EginUser.Instance;
    EginXTJ xtj = EginXTJ.Instance;
    public List<GameObject> ChooseStatus1;
    public List<GameObject> ChooseBtn1;
    public List<GameObject> ChooseStatus2;
    public List<GameObject> ChooseBtn2;

    public GameObject CreatRoomBtn;
    public GameObject CloseBtn;
    public GameObject ReplaceCreateBtn;
    //public GameObject GoldPatternBtn;
    //public GameObject RoomCardPatternBtn;
    //public GameObject GoldPatternObj;
    //public GameObject RoomCardPatternObj;


    private void Awake()
    {
        for (int i = 0; i < ChooseBtn1.Count; i++)
        {
            UIEventListener.Get(ChooseBtn1[i]).onClick = ButtonClick;
        }

        for (int i = 0; i < ChooseBtn2.Count; i++)
        {
            UIEventListener.Get(ChooseBtn2[i]).onClick = ButtonClick;
        }
       

        UIEventListener.Get(CreatRoomBtn).onClick = ButtonClick;
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
        UIEventListener.Get(ReplaceCreateBtn).onClick = ButtonClick;
        //UIEventListener.Get(GoldPatternBtn).onClick = ButtonClick;
        //UIEventListener.Get(RoomCardPatternBtn).onClick = ButtonClick;
    }
    void ButtonClick(GameObject button)
    {
                         
            if (button.name == "1")
            {
                ChooseStatus1[0].SetActive(true);
                ChooseStatus1[1].SetActive(false);
                ChooseStatus1[2].SetActive(false);

            }
            else if (button.name == "2")
            {
                ChooseStatus1[0].SetActive(false);
                ChooseStatus1[1].SetActive(true);
                ChooseStatus1[2].SetActive(false);

            }
            else if (button.name == "3")
            {
                ChooseStatus1[0].SetActive(false);
                ChooseStatus1[1].SetActive(false);
                ChooseStatus1[2].SetActive(true);
            }
            if (button.name == "4")
            {
                ChooseStatus2[0].SetActive(true);
                ChooseStatus2[1].SetActive(false);
                ChooseStatus2[2].SetActive(false);

            }
            else if (button.name == "5")
            {
                ChooseStatus2[0].SetActive(false);
                ChooseStatus2[1].SetActive(true);
                ChooseStatus2[2].SetActive(false);

            }
            else if (button.name == "6")
            {
                ChooseStatus2[0].SetActive(false);
                ChooseStatus2[1].SetActive(false);
                ChooseStatus2[2].SetActive(true);
            }
        

        if (button.name == "CreatRoomBtn")
        {
            SendCreatRoom(false);

        }
        else if (button.name == "ReplaceCreateRoomBtn")
        {
            SendCreatRoom(true);
        }
        else if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
              
    }
    void SendCreatRoom(bool isReplace)
    {
        int TotalRound = 4;
        //int BaseScore = 10000;
              
        
        for (int i = 0; i < ChooseStatus2.Count; i++)
        {
            if (ChooseStatus1[i].activeSelf)
            {
                Debug.Log("roomTypeId:" + i);
                if (i == 0)
                {
                    //BaseScore = 10000;
                    xtj.level = 0;
                }
                else if (i == 1)
                {
                    //BaseScore = 50000;
                    xtj.level = 1;
                }
                else if (i == 2)
                {
                    //BaseScore = 100000;
                    xtj.level = 2;
                }
            }

        }
        for (int i = 0; i < ChooseStatus2.Count; i++)
        {
            if (ChooseStatus2[i].activeSelf)
            {
                Debug.Log("roomTypeId:" + i);
                if (i == 0)
                {
                    TotalRound = 4;
                }
                else if (i == 1)
                {
                    TotalRound = 8;
                }
                else if (i == 2)
                {
                    TotalRound = 16;
                }
            }
            xtj.totalRound = TotalRound;
        }

                                      
        PaiEnterRoundRequest MR = new Pb.PaiEnterRoundRequest { RoundType = 3,Level = xtj.level,Rounds = TotalRound,Replace = isReplace};
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(MR, MsgId.PaiEnterRoundRequest);
        
    }

}
